<template>
    <div>
  <table class="table">
        <tbody>
           
        <tr>
            <td>图片</td>
            <td>
                <input type="file" @change="upload">
                <img style="width: 60px;height: 60px;":src="axios.defaults.baseURL+upddata.img" alt="">
            </td>
        </tr>
         <tr>
            <td>特色服务</td>
            <td>
                <select v-model="upddata.tid">
                    <option value="0">请选择</option>
                    <option v-for="d in Bang":value=d.tid>{{d.tname  }}</option>
                </select>
            </td>
        </tr>
         <tr>
            <td>营业时间</td>
            <td><input type="date" v-model="upddata.statetime"></td>
        </tr>
         <tr>
            <td>地址</td>
            <td><input type="text" v-model="upddata.addr"></td>
        </tr>
         <tr>
            <td>手机号</td>
            <td><input type="text" v-model="upddata.phone"></td>
        </tr>
         <tr>
            <td>状态</td>
            <td>
                <input type="radio" name="AAA" :value=true v-model="upddata.state">立即发布
                  <input type="radio"  name="AAA" :value=false v-model="upddata.state">稍后发布
            </td>
        </tr>
           <tr>
            <td>机构详情</td>
            <td><textarea v-model="upddata.ting"></textarea></td>
        </tr>
           <tr>
            <td></td>
            <td><input type="button" class="btn btn-success" value="保存" @click="Updlate"></td>
        </tr>
         </tbody>
      </table>
    </div>
</template>

<script setup lang="ts">
import {ref,onMounted} from 'vue'
import axios from 'axios'
import { useRoute,useRouter } from 'vue-router'
const route=useRoute()
const router=useRouter()
//上传文件
const upload=(abc:any)=>{
    let f=abc.target.files[0];
    let fd=new FormData();
    fd.append("file",f)
    axios.post("/api/Img/Upload",fd).then(res=>{
    upddata.value.img=res.data;
    })

}

onMounted(()=>{
    Type()
    Fang()
})

//反填
const Fang=()=>{
    var mid=route.query.id;
    axios.get("/api/Body/GetBody",{params:{id:mid}}).then(res=>{
        upddata.value=res.data
        upddata.value.statetime=res.data.statetime.substring(0,10);

    })
}

const Bang=ref([{
      "tid": 0,
    "tname": ""
}])
const Type=()=>{
    axios.get("/api/Type/GetTypes").then(res=>{
      Bang.value=res.data
    })
}

const upddata=ref({
     "id": 0,
  "code": "",
  "img": "",
  "tid": 0,
  "statetime": "",
  "addr": "",
  "phone": "",
  "state": "",
  "ting": ""
})

const Updlate=()=>{
    axios.put("/api/Body/UpdBody",upddata.value).then(res=>{
      if(res.data>0)
      {
        alert("修改成功")
router.push("/Showbody")
        
      }
      else
      {
         alert("修改失败")
      }
    })
}
















</script>

<style scoped>

</style>